﻿Imports System.Data.OleDb
Public Class PhieuXuatDAO
    Public Function GetPhieuXuat() As DataTable
        Dim sql As String = "select * from XuatNguyenLieu"
        Dim dt As New DataTable
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub AddPhieuXuat(ByVal newPX As PhieuXuatDTO)
        Dim sql As String = String.Format("insert into XuatNguyenLieu(MaNL,TenNL,NgayXuat,DonVi,SoLuong,KhoiLuong,DonGia,MaNV) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", _
                                           newPX.MaNL, newPX.TenNL, newPX.NgayXuat, newPX.DonVi, newPX.SoLuong, newPX.KhoiLuong, newPX.MaNV, newPX.DonGia)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Dữ liêu bị sai vui lòng kiểm tra lại !")
        End Try
        cn.Close()
    End Sub

    Public Sub DelPhieuXuat(ByVal delPX As PhieuXuatDTO)
        Dim sql As String = String.Format("delete from XuatNguyenLieu where MaNL={0}", delPX.MaNL)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub UpdatePhieuXuat(ByVal newPX As PhieuXuatDTO)
        Dim sql As String = String.Format("update XuatNguyenLieu set TenNL='{0}',NgayXuat='{1}',DonVi='{2}',SoLuong='{3}',KhoiLuong='{4}',DonGia='{5}',MaNV='{6}' where MaNL={7}", _
                                          newPX.TenNL, newPX.NgayXuat, newPX.DonVi, newPX.SoLuong, newPX.KhoiLuong, newPX.MaNV, newPX.DonGia, newPX.MaNL)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Vui lòng kiểu tra lại dữ liệu !")
        End Try
        cn.Close()
    End Sub
End Class
